﻿@model KPIS.GERP.Models.ICM.Received

@{
    ViewBag.Title = "รับพัสดุเข้าคลัง [RC]";
    ViewBag.Descr = "เพิ่มข้อมูลรับพัสดุเข้าคลัง";

}


@using (Html.BeginForm("Create", "ReceiveParcel", FormMethod.Post, new { id = "form", @class = "form-horizontal" }))
{
   @Html.AntiForgeryToken()

    <div class="span12 block-button-menu-above">
        @Html.ButtonViewAll()
        @Html.ButtonSubmit()
    </div>

    @Html.ValidationSummary(true, KPIS.GERP.Models.Class.ValidateText.RequiredField, new { @class = "alert alert-error" })
    @Html.Partial("_EditorForm")
}

@section scripts {



    <script type="text/javascript" >

        //$(".chzn-select").chosen();
        //$(".chzn-select-deselect").chosen({ allow_single_deselect: true });

        function DisableDN() {
            var Type = $("#ddlRecType option:selected").val();
            if (Type == "3") {
                $("#dvDn").show();
                $("#dvWhByDn").show();
                $("#dvWh").hide();
            } else {
                $("#dvDn").hide();
                $("#dvWhByDn").hide();
                $("#dvWh").show();
            }
        }

        $("form").submit(function(e) {
            e.preventDefault();
            var currentForm = this;
            bootbox.confirm("ต้องการบันทึก ใช่หรือไม่?", function(result) {
                if (result) {
                    var Type = $("#ddlRecType option:selected").val();
                    if (Type == "3") {
                        var DnId = $("#ddlDn option:selected").val();
                        var Name = $("#txtRecName").val();

                        if (DnId == 0 || Name == "") {

                            if (DnId == 0) {
                                $("#txtDN").show();
                            } else {
                                $("#txtDN").hide();
                            }

                            if (Name == "") {
                                $("#txtName").show();
                            } else {
                                $("#txtName").hide();
                            }

                        } else {
                            currentForm.submit();
                        }
                    } else {

                        var WhId = $("#ddlWh option:selected").val();
                        var Name = $("#txtRecName").val();

                        if (WhId == 0 || Name == "") {

                            if (WhId == 0) {
                                $("#txtWh").show();
                            } else {
                                $("#txtWh").hide();
                            }

                            if (Name == "") {
                                $("#txtName").show();
                            } else {
                                $("#txtName").hide();
                            }

                        } else {
                            $("#hdWhId").val(WhId);
                            currentForm.submit();
                        }
                    }
                }
            });
        });

        $(function() {
            var DnId = $("#ddlDn option:selected").val();
            SetDnLink(DnId);
        });
        
        function SetDnLink(DnId) {
            if (DnId == 0) {
                $('#clickOpenDn').hide();
            } else {
                $('#clickOpenDn').show();
                $('#clickOpenDn').attr('href', '@Url.Action("Details", "DeliveryNote")/?dnid=' + DnId);
            }
        }

        // Fetch Warehouse เมื่อเลือกใบตรวจรับ
        function FetchWarehouse() {
            var DnId = $("#ddlDn option:selected").val();

            if (DnId == 0) {
                $("#txtWhName").val("");
                $('#clickOpenDn').hide();
            } else {
                $.getJSON('@Url.Action("GetWareHouse", "Receiveparcel")?intDnId=' + DnId, null, function(data) {
                    $("#hdWhId").val(data.Id);
                    $("#txtWhName").val(data.Name);
                });
                SetDnLink(DnId);
            }
        }

    </script>
}


